<?php
// lib/RedisPool.php

namespace Tyrone\Lib;

use Swoole\Coroutine\Channel;
use Swoole\Coroutine\Redis;

class FetchConfigByMsql
{
    private $pool;
    private $config;
    private $timeout;

    public function __construct($config)
    {
        $this->config = $config;
    }
    public function getConfig()
    {

        $client = new Swoole\Coroutine\MySQL();
        $connected = $client->connect($this->config);

        if (!$connected) {
            echo "MySQL connect failed: " . $client->connect_error . "\n";
            return [];
        }

        /*$sql = "";
        $stmt = $client->prepare("SELECT id, host, port, `database`, username, password, server_name FROM servers WHERE status = 1");
        if (!$stmt) {
            echo "Prepare failed: " . $client->error . "\n";
            return [];
        }

        $result = $stmt->execute();
        if ($result === false) {
            echo "Query failed: " . $client->error . "\n";
            return [];
        }

        $rows = $stmt->fetchAll();*/
        $client->close();
        return $rows ?? [$this->config];
    }
}